home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / ViePratique / ArchiFacile / ArchiFacileSetup.exe / {app} / nw.pak / Unnamed File 001164.txt < prev    next >
Text File  |  2014-10-14  |  5KB  |  141 lines

  1. // Copyright (c) 2012 Intel Corp
  2. // Copyright (c) 2012 The Chromium Authors
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. //  in the Software without restriction, including without limitation the rights
  7. //  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
  8. // pies of the Software, and to permit persons to whom the Software is furnished
  9. //  to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in al
  12. // l copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
  15. // PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
  16. // S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  17. //  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
  18. // ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  
  21. var v8_util = process.binding('v8_util');
  22.  
  23. function Tray(option) {
  24.   if (typeof option != 'object')
  25.     throw new String('Invalid option');
  26.  
  27.   if (!option.hasOwnProperty('title') && !option.hasOwnProperty('icon'))
  28.     throw new String("Must set 'title' or 'icon' field in option");
  29.  
  30.   if (!option.hasOwnProperty('title'))
  31.     option.title = '';
  32.   else
  33.     option.title = String(option.title);
  34.  
  35.   if (option.hasOwnProperty('icon')) {
  36.     option.shadowIcon = String(option.icon);
  37.     option.icon = nw.getAbsolutePath(option.icon);
  38.   }
  39.  
  40.   if (option.hasOwnProperty('alticon')) {
  41.     option.shadowAlticon = String(option.alticon);
  42.     option.alticon = nw.getAbsolutePath(option.alticon);
  43.   }
  44.  
  45.   if (option.hasOwnProperty('tooltip'))
  46.     option.tooltip = String(option.tooltip);
  47.  
  48.   if (option.hasOwnProperty('click')) {
  49.     if (typeof option.click != 'function') {
  50.       throw new String("'click' must be a valid Function");
  51.     } else {
  52.       this.click = option.click;
  53.     }
  54.    }
  55.  
  56.   if (option.hasOwnProperty('menu')) {
  57.     if (v8_util.getConstructorName(option.menu) != 'Menu')
  58.       throw new String("'menu' must be a valid Menu");
  59.  
  60.     // Transfer only object id
  61.     v8_util.setHiddenValue(this, 'menu', option.menu);
  62.     option.menu = option.menu.id;
  63.   }
  64.  
  65.   v8_util.setHiddenValue(this, 'option', option);
  66.   nw.allocateObject(this, option);
  67.  
  68.   // All properties must be set after initialization.
  69.   if (!option.hasOwnProperty('icon'))
  70.     option.shadowIcon = '';
  71.   if (!option.hasOwnProperty('alticon'))
  72.     option.shadowAlticon = '';
  73.   if (!option.hasOwnProperty('tooltip'))
  74.     option.tooltip = '';
  75. }
  76. require('util').inherits(Tray, exports.Base);
  77.  
  78. Tray.prototype.__defineGetter__('title', function() {
  79.   return this.handleGetter('title');
  80. });
  81.  
  82. Tray.prototype.__defineSetter__('title', function(val) {
  83.   this.handleSetter('title', 'SetTitle', String, val);
  84. });
  85.  
  86. Tray.prototype.__defineGetter__('icon', function() {
  87.   return this.handleGetter('shadowIcon');
  88. });
  89.  
  90. Tray.prototype.__defineGetter__('alticon', function() {
  91.   return this.handleGetter('shadowAlticon');
  92. });
  93.  
  94. Tray.prototype.__defineSetter__('icon', function(val) {
  95.   v8_util.getHiddenValue(this, 'option').shadowIcon = String(val);
  96.   var real_path = val == '' ? '' : nw.getAbsolutePath(val);
  97.   this.handleSetter('icon', 'SetIcon', String, real_path);
  98. });
  99.  
  100. Tray.prototype.__defineSetter__('alticon', function(val) {
  101.   v8_util.getHiddenValue(this, 'option').shadowAlticon = String(val);
  102.   var real_path = val == '' ? '' : nw.getAbsolutePath(val);
  103.   this.handleSetter('alticon', 'SetAlticon', String, real_path);
  104. });
  105.  
  106. Tray.prototype.__defineGetter__('tooltip', function() {
  107.   return this.handleGetter('tooltip');
  108. });
  109.  
  110. Tray.prototype.__defineSetter__('tooltip', function(val) {
  111.   this.handleSetter('tooltip', 'SetTooltip', String, val);
  112. });
  113.  
  114. Tray.prototype.__defineGetter__('menu', function() {
  115.   return v8_util.getHiddenValue(this, 'menu');
  116. });
  117.  
  118. Tray.prototype.__defineSetter__('menu', function(val) {
  119.   if (v8_util.getConstructorName(val) != 'Menu')
  120.     throw new String("'menu' property requries a valid Menu");
  121.  
  122.   v8_util.setHiddenValue(this, 'menu', val);
  123.   nw.callObjectMethod(this, 'SetMenu', [ val.id ]);
  124. });
  125.  
  126. Tray.prototype.remove = function() {
  127.   nw.callObjectMethod(this, 'Remove', []);
  128. }
  129.  
  130. Tray.prototype.handleEvent = function(ev) {
  131.  if (ev == 'click') {
  132.    // Emit click handler
  133.    if (typeof this.click == 'function'){
  134.      this.click();
  135.    }
  136.  }
  137.  // Emit generate event handler
  138.  exports.Base.prototype.handleEvent.apply(this, arguments);
  139. }
  140. exports.Tray = Tray;
  141.